package com.spdd.mt.app.api;

import com.spdd.mt.app.aop.sign.ValidateSign;
import com.spdd.mt.biz.manager.model.request.PhoneZoneRequest;
import com.spdd.mt.biz.manager.model.request.ProductQueryRequest;
import com.spdd.mt.biz.manager.model.request.ProductStatusRequest;
import com.spdd.mt.biz.manager.model.response.PhoneZoneResponse;
import com.spdd.mt.biz.manager.model.response.ProductQueryResponse;
import com.spdd.mt.biz.manager.model.response.ProductStatusResponse;
import com.spdd.mt.biz.manager.service.ProductService;
import com.spdd.mt.common.util.JacksonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 商品查询接口
 */
@Slf4j
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 查询单个商品的状态信息
     *
     * @param statusRequest 查询请求参数
     * @param request       http请求对象
     */
    @ValidateSign
    @PostMapping(value = "/query")
    public ProductStatusResponse productMaintenance(@RequestBody @Validated ProductStatusRequest statusRequest, HttpServletRequest request) {
        log.info("商品维护信息查询接口，请求参数:{}", JacksonUtils.toJson(statusRequest));

        ProductStatusResponse response = productService.productStatusQuery(statusRequest);

        log.info("商品维护信息查询接口响应为:{}", JacksonUtils.toJson(response));

        return response;
    }

    /**
     * 查询商品和维护信息接口
     *
     * @param queryRequest 查询请求参数
     * @param request      http请求对象
     */
    @ValidateSign
    @PostMapping(value = "/query-all")
    public ProductQueryResponse productQuery(@RequestBody @Validated ProductQueryRequest queryRequest, HttpServletRequest request) {
        log.info("商品查询接口，请求参数:{}", JacksonUtils.toJson(queryRequest));

        ProductQueryResponse response = productService.productQuery(queryRequest);

        log.info("商品查询接口响应为:{}", JacksonUtils.toJson(response));

        return response;
    }

    /**
     * 手机号码归属地查询接口
     *
     * @param zoneRequest 查询请求参数
     * @param request     http请求对象
     */
    @ValidateSign
    @PostMapping(value = "/phone-zone")
    public PhoneZoneResponse phoneZone(@RequestBody @Validated PhoneZoneRequest zoneRequest, HttpServletRequest request) {
        log.info("手机号码归属地查询接口，请求参数:{}", JacksonUtils.toJson(zoneRequest));

        PhoneZoneResponse response = productService.phoneZoneQuery(zoneRequest);

        log.info("手机号码归属地查询接口响应为:{}", JacksonUtils.toJson(response));

        return response;
    }

}
